package cuit.game.entity;

import java.util.ArrayList;
import java.util.List;


import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

@Entity
@Table(name="t_user")
public class User extends BaseEntity{ 
   
	@Column(name="username")
    private String username;
    @Column(name="password")
    private String pwd;
    @Column(name="email")
    private String email;
    @Column(name="captain")
    private long captain = 0;
    @OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private List<Picture> pictures = new ArrayList<Picture>();
    @OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private List<Application> applications = new ArrayList<Application>();
    @OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private List<Team> teams = new ArrayList<Team>();
 // getter 和 setter 方法
    public List<Application> getApplications() {
        return applications;
    }

    public void setApplications(List<Application> applications) {
        if (applications == null || applications.isEmpty()) {
            this.applications = new ArrayList<>();
        } else if (this.applications == null || applications.size() != 0) {
            this.applications = new ArrayList<>();
            this.applications.addAll(applications);
        } else {
            this.applications.clear();
            this.applications.addAll(applications);
        }
    }
    public List<Team> getTeams() {
        return teams;
    }
    public void setTeams(List<Team> teams) {
        if (teams == null || teams.isEmpty()) {
            this.teams = new ArrayList<>();
        } else if (this.teams == null || teams.size() != 0) {
            this.teams = new ArrayList<>();
            this.teams.addAll(teams);
        } else {
            this.teams.clear();
            this.teams.addAll(teams);
        }
    }
    public List<Picture> getPictures() {
        return pictures;
    }

    public void setPictures(List<Picture> pictures) {
        if (pictures == null || pictures.isEmpty()) {
            this.pictures = new ArrayList<>();
        } else if (this.pictures == null || pictures.size() != 0) {
            this.pictures = new ArrayList<>();
            this.pictures.addAll(pictures);
        } else {
            this.pictures.clear();
            this.pictures.addAll(pictures);
        }
    }
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

	public long getCaptain() {
		return captain;
	}

	public void setCaptain(long captain) {
		this.captain = captain;
	}

	@Override
	public String toString() {
		return "User [username=" + username + ", pwd=" + pwd + ", email=" + email + ", captain=" + captain
				+ ", applications=" + applications + ", teams=" + teams + "]";
	}

}
